<?php
class Admin_Model_Question{
	
	private $question;
	
	function __construct(){
		$this->question = new Admin_Model_DbTable_Cauhois();
	}
	
	/**
	 * 
	 * Liet ket tat ca cac cau hoi
	 * @param unknown_type $where
	 */
	public function listQuestion($where=null){
		if($where != null){
			return $this->question->select()->where($where)->order('idCauHoi DESC');	
		}else{
			return $this->question->select()->order('idCauHoi DESC');
		}
	}
	
	/**
	 * 
	 * Them cau hoi moi
	 * @param unknown_type $nameQuestion : ten cau hoi
	 * @param unknown_type $idMonHoc: mon hoc (id)
	 * @param unknown_type $a : dap an a
	 * @param unknown_type $b : dap an b
	 * @param unknown_type $c : dap an c
	 * @param unknown_type $d : dap an d
	 * @param unknown_type $e : dap an e
	 * @param unknown_type $trueQuestion : dap an dung
	 * @param unknown_type $level : muc do
	 * 
	 * @return mixed primary of row inserted
	 */
	public function addQuestion($nameQuestion, $idMonHoc, $a, $b, $c, $d=null, $e=null, $trueQuestion,$level="trungBinh"){
		$data = array(
			'tenCauHoi'		=>	$nameQuestion,
			'idMonHoc'		=>	$idMonHoc,
			'a'				=>	$a,
			'b'				=>	$b,
			'c'				=>	$c,
			'd'				=>	$d,
			'e'				=>	$e,
			'dapAnDung'		=>	$trueQuestion,
			'mucDo'			=>	$level
		);
		
		$this->question->insert($data);
	}
	
	/**
	 * 
	 * Them cau hoi moi
	 * @param unknown_type $nameQuestion : ten cau hoi
	 * @param unknown_type $idMonHoc: mon hoc (id)
	 * @param unknown_type $a : dap an a
	 * @param unknown_type $b : dap an b
	 * @param unknown_type $c : dap an c
	 * @param unknown_type $d : dap an d
	 * @param unknown_type $e : dap an e
	 * @param unknown_type $trueQuestion : dap an dung
	 * @param unknown_type $level : muc do
	 * @param $id :  ma cau hoi
	 * @return mixed primary of row inserted
	 */
	public function updateQuestion($nameQuestion, $idMonHoc, $a, $b, $c, $d, $e, $trueQuestion,$level="trungBinh",$id){
		$data = array(
			'tenCauHoi'		=>	$nameQuestion,
			'idMonHoc'		=>	$idMonHoc,
			'a'				=>	$a,
			'b'				=>	$b,
			'c'				=>	$c,
			'd'				=>	$d,
			'e'				=>	$e,
			'dapAnDung'		=>	$trueQuestion,
			'mucDo'			=>	$level
		);
		
		$this->question->update($data,'idCauHoi ='.$id);
	}
	
	/**
	 * 
	 * Xoa cau hoi
	 * @param unknown_type $id : ma cau hoi
	 */
	public function deleteQuestion($id){
		$this->question->delete('idCauHoi = '.$id);
	}
	
	/**
	 * 
	 * ham update mac dinh cua zend
	 * @param unknown_type $data : Array
	 * @param unknown_type $where : 
	 */
	public function update($data,$where){
		$this->question->update($data, $where);
	}
	
	public function fetchQuestion($id){
		return $this->question->fetchRow('idCauHoi = '.$id);	
	}
}